<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
<title></title>
<meta name="viewport"
	content="width=device-width, initial-scale=1.0, maximum-scale=1, user-scalable=no">
<meta name="description" content="">
<meta name="author" content="">
<!-- STYLESHEETS -->
<!--[if lt IE 9]>
    <script src="../../js/flot/excanvas.min.js"></script>
    <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
    <script src="http://css3-mediaqueries-js.googlecode.com/svn/trunk/css3-mediaqueries.js"></script><![endif]-->
<link rel="stylesheet" type="text/css" href="../../css/cloud-admin.css">
<link rel="stylesheet" type="text/css" href="../../css/themes/default.css" id="skin-switcher">
<link rel="stylesheet" type="text/css" href="../../css/responsive.css">
<link href="../../font-awesome/css/font-awesome.min.css" rel="stylesheet">
<!-- SELECT2 -->
<link rel="stylesheet" type="text/css" href="../../js/select2/select2.min.css" />
<!-- file-input -->
<link rel="stylesheet" type="text/css" href="../../js/file-input/fileinput.css" />
<!-- UNIFORM -->
<link rel="stylesheet" type="text/css" href="../../js/uniform/css/uniform.default.min.css" />
<!-- datatable -->
<link rel="stylesheet" href="../../js/datatables/datatable.css">
<link rel="stylesheet" href="../../js/datepicker/datepicker.css">
<!-- JQUERY -->
<script src="../../js/jquery/jquery-2.0.3.min.js"></script>
<script type="text/javascript" src="../../js/datepicker/datepicker.js"></script>
<script src="../../js/common.js"></script>
</head>
<body>
	<header class="navbar clearfix" id="header"> </header>

	<!-- PAGE -->
	<section id="page">
		<!-- SIDEBAR -->
		<div id="sidebar" class="sidebar">
			<div class="sidebar-menu nav-collapse">

				<!-- SIDEBAR MENU -->
				<ul>

				</ul>
				<!-- /SIDEBAR MENU -->
			</div>

		</div>
		<!-- /SIDEBAR -->
		<div id="main-content">
			<!-- SAMPLE BOX CONFIGURATION MODAL FORM-->
			<div class="modal fade" id="box-config" tabindex="-1" role="dialog"
				aria-labelledby="myModalLabel" aria-hidden="true">
				<div class="modal-dialog">
					<form id="form_focus">
						<div class="modal-content">
							<div class="modal-header">
								<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
								<h4 class="modal-title">上传合同扫描件</h4>
							</div>
							<div class="modal-body">
								<div class="form-group  mrg-bt10">
									<input type="hidden" name="id" />
									<label class="control-label col-md-3" style="line-height: 34px;">合同编号：</label>
									<div class="col-md-6 contractCode"></div>
								</div>
								<div class="form-group  mrg-bt10" style="height: 100px">
									<label class="control-label col-md-3" style="line-height: 34px;">
										<span class="required">*</span>
										上传文件：
									</label>
									<form>
										<div class="col-md-8">
											<div hidden-image></div>
											<div class="fileinput fileinput-new" data-provides="fileinput">

												<div style="float: left; margin-left: 5px;" class="addnewimg" id="f_span">
													<span class="btn btn-default btn-file" id="fir">
														<span class="fileinput-new" id="two">上传图片</span>
														<span class="fileinput-exists">Change</span>
														<input type="file" name="uploadFile" upload-file="imageUrlProduct">
													</span>
													<div class="progress progress-striped active" role="progressbar" aria-valuemin="0"
														aria-valuemax="100" style="margin-bottom: 0px; margin-top: 10px;">
														<div class="progress-bar progress-bar-success" style="width: 0%;"></div>
													</div>
												</div>

											</div>


										</div>
									</form>

								</div>
								<div class="modal-footer">
									<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>

								</div>

							</div>

						</div>
					</form>

				</div>
			</div>
			<!-- /SAMPLE BOX CONFIGURATION MODAL FORM-->
			<!--- 归档弹窗-->
			<div class="modal fade" id="archivedBox" tabindex="-1" role="dialog"
				aria-labelledby="myModalLabel" aria-hidden="true">
				<div class="modal-dialog">
					<div class="modal-content">
						<div class="modal-header">
							<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
							<h4 class="modal-title">归档</h4>
						</div>
						<div class="modal-body">
							<div class="form-group">
								<label class="control-label col-md-3" style="line-height: 34px;">
									<span class="required">*</span>
									协议编号：
								</label>
								<div class="col-md-8">
									<input type="text" class="form-control" name="contractCode" placeholder="请输入协议编号"
										maxlength="20" />
									<input type="hidden" name="id" />
								</div>
							</div>
						</div>
						<div class="modal-footer">
							<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
							<button type="button" class="btn btn-success bt-save">保存</button>
						</div>
					</div>
				</div>
			</div>

			<!--- 备注弹窗-->
			<div class="modal fade" id="remarkBox" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
				aria-hidden="true">
				<div class="modal-dialog">
					<div class="modal-content">
						<div class="modal-header">
							<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
							<h4 class="modal-title">添加备注</h4>
						</div>
						<div class="modal-body">
							<div class="form-group">
								<label class="control-label col-md-3" style="line-height: 34px;">
									<span class="required">*</span>
									备注：
								</label>
								<div class="col-md-8">
									<textarea name="remark" placeholder="请输入备注" style="width: 100%;" rows=3></textarea>
									<input type="hidden" name="id" />
								</div>
							</div>
						</div>
						<div class="modal-footer">
							<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
							<button type="button" class="btn btn-success bt-save">保存</button>
						</div>
					</div>
				</div>
			</div>




			<div class="container">
				<div class="row">
					<div id="content" class="col-lg-12">
						<!-- PAGE HEADER-->
						<div class="row">
							<div class="col-sm-12">
								<div class="page-header">
									<!-- STYLER -->

									<!-- /STYLER -->

									<!-- /BREADCRUMBS -->

								</div>
							</div>
						</div>


						<div class="row">
							<!-- TABLES -->
							<div class="col-md-12">
								<!-- BOX -->
								<div class="box border primary">
									<div class="box-title">
										<h4>
											<i class="fa fa-table"></i>
											补充协议
										</h4>

									</div>
									<div class="box-body">
										<table id="db_coupon_list" cellpadding="0" cellspacing="0" border="0"
											class="datatable table table-striped table-bordered table-hover"
											style="word-break: break-all; word-wrap: break-word;">

										</table>
									</div>
								</div>
								<!-- /BOX -->
							</div>
						</div>
						<!-- /TABLES -->


						<div class="footer-tools">
							<span class="go-top">
								<i class="fa fa-chevron-up"></i>
								Top
							</span>
						</div>
					</div>
					<!-- /CONTENT-->
				</div>
			</div>
		</div>
	</section>
	<!--/PAGE -->
	<!-- JAVASCRIPTS -->
	<!-- Placed at the end of the document so the pages load faster -->

	<script src="../../js/jquery-ui-1.10.3.custom/js/jquery-ui-1.10.3.custom.min.js"></script>
		<!-- BOOTSTRAP -->
		<script src="../../bootstrap-dist/js/bootstrap.min.js"></script>

		<!-- BLOCK UI -->
		<script type="text/javascript" src="../../js/jQuery-BlockUI/jquery.blockUI.min.js"></script>
		
		<!-- AUTOSIZE -->
		<script type="text/javascript" src="../../js/autosize/jquery.autosize.min.js"></script>
	
		<!-- INPUT MASK -->
		<script type="text/javascript" src="../../js/bootstrap-inputmask/bootstrap-inputmask.min.js"></script>
		<!-- SELECT2 -->
		<script type="text/javascript" src="../../js/select2/select2.min.js"></script>
	   
	     <!-- bootstrap-fileupload -->
	    <script type="text/javascript" src="../../js/jquery-upload/js/jquery.iframe-transport.js"></script>
	    <script type="text/javascript" src="../../js/jquery-upload/js/jquery.fileupload.min.js"></script>
	    <script type="text/javascript" src="../../js/jquery-upload/js/jquery.fileupload-process.min.js"></script> 
	    <script type="text/javascript" src="../../js/jquery-upload/js/jquery.fileupload-validate.min.js"></script>
	    
		<!-- UNIFORM -->
		<script type="text/javascript" src="../../js/uniform/jquery.uniform.min.js"></script>
		<!-- spinner -->
		<script src="../../js/spinner/spin.js"></script>
		<!-- DATA TABLES -->
		<script type="text/javascript" src="../../js/datatables/bootstrap-select.js"></script>
		<script type="text/javascript" src="../../js/datatables/datatable.js"></script>
		<script type="text/javascript" src="../../js/datatables/datatable-bootstrap.js"></script>
		<script type="text/javascript" src="../../js/datatables/datatable-tabletools.js"></script>
		<script type="text/javascript" src="../../js/datatables/fnAddTr.js"></script>

		<!--bootbox-->
		<script type="text/javascript" src="../../js/bootbox/bootbox.min.js"></script>
		<!-- COOKIE -->
		<script type="text/javascript" src="../../js/jQuery-Cookie/jquery.cookie.min.js"></script>
		<!-- CUSTOM SCRIPT -->
		<script src="../../js/script.js"></script>
		<style>
		.wd{display: flex; }
		</style>
	<script>
		var Coupon = function() {
			var $mainDataTable = null;
			var contractType = $.getUrlParam("contractType");
			var changeContractCode = $.getUrlParam("changeContractCode");

			$(".addBtn").click(
					function() {
						location.href = "add_contract.html?contractType="
								+ contractType;
					});

			var search = function() {

				var startDate = $("input[name=startDate]").val();
				var endDate = $("input[name=endDate]").val();
				var q = $("input[name=q]").val();
				var status = $("#status_select").val();
				var url = App.getContextPath()
						+ "admin/contract/searchSettlementContract.do?changeContractCode="
						+ changeContractCode;

				if ($mainDataTable) {
					$mainDataTable.api().ajax.url(url).load();
					return;
				}
				var dtSetting = $
						.dataTableSetting({
							"ajaxSource" : url,
							"serverSide" : true,
							"bFilter" : false,// 去掉搜索框
							"bLengthChange" : true,// 每页显示数量
							"sScrollX" : "100%",
							"sScrollXInner" : "100%",
							"iDisplayLength" : 10,
							"bSort" : false,
							"aoColumns" : [
									{
										"mDataProp" : "id",
										"sTitle" : "ID",
										"width" : "6%"

									},
									{
										"mDataProp" : "contractCode",
										"sTitle" : "补充协议编号",
										"width" : "10%"

									},
									{
										"mDataProp" : "changeContractCode",
										"sTitle" : "合同编号",
										"width" : "10%"

									},
									{
										"sTitle" : "创建时间",
										"mDataProp" : "createTime",
										"width" : "6%",
										"render" : function(data, type, row) {
											return $
													.getLocalDate(row.createTime);
										}
									},
									{
										"sTitle" : "创建人",
										"mDataProp" : "createBy",
										"width" : "6%"
									},
									{
										"sTitle" : "状态",
										"mDataProp" : "contractStatus",
										"width" : "6%",
										"render" : function(data, type, row) {
											if (row.contractStatus == 'NotArchived') {
												return "未归档";
											} else if (row.contractStatus == 'Archived') {
												return "已归档";
											} else if (row.contractStatus == 'Cancel') {
												return "作废";
											}
										}
									},
									{
										"sTitle" : "操作",
										"width" : "15%",
										
										"render" : function(data, type, row) {

											var str = "";
											str += "<a class='btn  btn-success btn-xs btn-width' style='width:60px;margin-left:5px' href='add_settlement_contract.html?changeContractCode="
													+ row.changeContractCode
													+ "&opType=view&id="
													+ row.id
													+ "'><i class='fa fa-arrow-circle-o-up'></i>查看</a>";
											if (row.contractStatus != 'Cancel') {
												str += "<a class='btn btn-warning btn-xs btn-width remarkBtn' style='width:60px;margin-left:5px' href='javascript:void(0)' content='"
														+ row.remark
														+ "' contractId='"
														+ row.id
														+ "'></i>备注</a>";
											}

											if (row.contractStatus == 'NotArchived') {
												str += "<a class='btn btn-primary btn-xs btn-width editBtn' style='width:60px;margin-left:5px' href='add_settlement_contract.html?id="
														+ row.id
														+ "&opType=edit&changeContractCode="
														+ row.changeContractCode
														+ "'><i class='fa fa-arrow-circle-o-up'></i>修改</a>";
												if (App
														.checkButton("MaterialContract:Archived")) {
													str += "<a class='btn btn-success btn-xs btn-width   archivedBtn' style='width:60px;margin-left:5px' href='javascript:void(0)' contractId='"
															+ row.id
															+ "'></i>归档</a>";
												}
												str += "<a class='btn btn-danger btn-xs btn-width delBtn' style='width:60px;margin-left:5px' href='javascript:void(0)' contractId='"
														+ row.id
														+ "'><i class='fa fa-arrow-circle-o-up'></i>删除</a>";
											}
											if (row.contractStatus == 'Archived'&&row.changeContractCode!=row.contractCode) {
												if (row.isUpload) {
													str += "<a class='btn btn-warning btn-xs btn-width download' style='width:60px ;margin-left:10px' contractCode="
														+ row.contractCode
														+ " href='javascript:void(0)' ></i>下载<form style='width:60px' id="
															+ row.contractCode
															+ " action='../../admin/contract/downloadContract.do?contractCode="
															+ row.contractCode
															+ "&fileType=ChangeContract'></form></a>";

												} else {
													str += "<a class='btn btn-warning btn-xs btn-width upload' style='width:60px ;margin-left:5px' href='javascript:void(0)' contractCode='"
															+ row.contractCode
															+ "' id='"
															+ row.id
															+ "'></i>上传</a>";
												}
											}
											
											return str;
										}
									} ]
						});

				$mainDataTable = $("#db_coupon_list").dataTable(dtSetting);
			};
			var contractCode = "";
			var id = "";
			var fileUpLoad = function() {

				$(".progress").hide();
				$("[upload-file=imageUrlProduct]").fileupload(
						{
							url : App.getContextPath()
									+ "admin/contract/upLoadContract.do",
							formData : {
								fileType : "ChangeContract",
								contractCode : contractCode,
								id : id
							},
							dataType : 'json',
							acceptFileTypes : /(\.|\/)(pdf)$/i,
							iframe : true,
							start : function(e) {
								$('.progress').fadeIn(300);
								return true;
							},
							autoUpload : true,
							done : function(e, data) {
								$("#box-config").modal("hide");
								$.alert("上传成功");
								search();

							},
							progressall : function(e, data) {
								var progress = parseInt(data.loaded
										/ data.total * 100, 10);
								$('.progress .progress-bar').css('width',
										progress + '%');
							}
						}).on('fileuploaddone', function(e, data) {
					$(".progress").fadeOut(300);

				});

			};
			var checkButton = function() {

			}
			return {
				init : function() {
					$.initDate($("#form_contract"), -30, 31);
					$("#status_select").select2({
						placeholder : "选择状态"
					});

					checkButton();

					$(".search").click(search);
					search();

					//删除
					$("body")
							.on(
									"click",
									".delBtn",
									function() {
										var _this = $(this);
										$
												.confirm(
														"确定要删除吗?",
														function() {

															$
																	.ajax({
																		type : "get",
																		url : App
																				.getContextPath()
																				+ "admin/contract/deleteSettlementContract.do?id="
																				+ _this
																						.attr("contractId"),
																		success : function(
																				data) {
																			if (data.type == "error") {
																				$
																						.alert(data.extra);
																			} else {
																				search();
																			}
																		}
																	});

														});
									})

					//归档
					$("body").on(
							"click",
							".archivedBtn",
							function() {
								var _this = $(this);
								$("#archivedBox").modal("show");
								$("#archivedBox").find("[name=id]").val(
										_this.attr("contractId"));

							})

					$("#archivedBox .bt-save")
							.click(
									function() {
										var id = $("#archivedBox").find(
												"[name=id]").val();
										var code = $("#archivedBox").find(
												"[name=contractCode]").val();
										if (code == "") {
											$.alert("请输入合同编号");
											return;
										}
										$
												.ajax({
													type : "get",
													url : App.getContextPath()
															+ "admin/contract/archivedSettlementContract.do?id="
															+ id
															+ "&contractCode="
															+ code,
													success : function(data) {
														$("#archivedBox")
																.modal("hide");
														$("#archivedBox").find(
																"input")
																.val("");
														$("#archivedBox").find(
																"textarea")
																.val("");
														if (data.type == "error") {
															$.alert(data.extra);
														} else {
															search();
														}
													}
												});
									});

					//备注
					$("body")
							.on(
									"click",
									".remarkBtn",
									function() {
										var _this = $(this);
										$("#remarkBox").modal("show");
										$("#remarkBox").find("[name=id]").val(
												_this.attr("contractId"));
										$("[name=remark]").val(
												$(this).attr("content"));
									})
					//上传
					$("body").on(
							"click",
							".upload",
							function() {
								contractCode = $(this).attr("contractcode");
								id = $(this).attr("id");
								fileUpLoad();
								$("#box-config").find("[name=id]").val(id);
								$("#box-config").find(".contractCode").html(
										contractCode);
								$("#box-config").modal("show");

							})
					//下载
					$("body")
							.on(
									"click",
									".download",
									function() {
										contractCode = $(this).attr(
												"contractcode");
										$(this).find("form")											
												.append(
														"<input type='hidden' name=contractCode value='"+contractCode+"'/>")
										$(this).find("form")
												.append(
														"<input type='hidden' name=fileType value='ChangeContract'/>")
										$(this).find("form").submit();

									})

					$("#remarkBox .bt-save")
							.click(
									function() {
										var id = $("#remarkBox").find(
												"[name=id]").val();
										var remark = $("#remarkBox").find(
												"[name=remark]").val();
										$
												.ajax({
													type : "get",
													url : App.getContextPath()
															+ "admin/contract/updateSettlementRemark.do?id="
															+ id + "&remark="
															+ remark,
													success : function(data) {
														$("#remarkBox").modal(
																"hide");
														$("#remarkBox").find(
																"input")
																.val("");
														$("#remarkBox").find(
																"textarea")
																.val("");
														search();
													}
												});
									});

				}
			}
		}();

		$(function() {
			$("#header").load("../head.html");
			App.init(); //Initialise plugins and elements
			Coupon.init();

		});
	</script>
	<!-- /JAVASCRIPTS -->
</body>
</html>